package com.zhaoyue.jvm;


import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 2017/1/19
 * Time: 14:49
 * To change this template use File | Settings | File Templates.
 */
public class DirectMemoryOOM {

    private static final int _1MB = 1024 * 1024;


    public static void main(String[] args) throws Exception {

        //对外内存，受限于机器
        Field field = Unsafe.class.getDeclaredFields()[0];
        field.setAccessible(true);
        Unsafe unsafe = (Unsafe)field.get(null);
        while (true){
            System.out.println("--------------");
            unsafe.allocateMemory(_1MB);
        }
    }

}
